<style type="text/css">
.button_login{
	bottom:0;
	right:0;
	cursor:pointer;
	position:absolute;
	float:left;
	width:130px;
	height:45px;
	background:url('/image/global/button_login.png');
}
.button_login:hover{background-position:0 -45px;}
</style>
<script type="text/javascript">
function validateUsername(){
	var username = $("#form_login #login_input_username").val();
	if (username.match("@") == null){
		if (!isValidMobile(username)) return false;
		return true;
	}  else {
		if (!isValidEmail(username)) return false;
		return true;
	}  
}
function validatePassword(){
	var password = $("#form_login #login_input_password").val();
	return isValidPassword(password);
}
$(document).ready(function(){
	$("#form_login").validationEngine();

	$("#button_login").click(function(){
		$.validationEngine.submitValidation("#form_login"); 
		var obj = this;
		var username = $("#form_login #login_input_username").val();
		var password = $("#form_login #login_input_password").val();
		if (!validateUsername()) return;
		if (!validatePassword()) return;
		$.validationEngine.buildPrompt("form #button_login", "正在提交，请稍候。", "load");
		$.post("/login/getLoginCode", function(data){
			password = hex_sha512(data + hex_sha512(password));
			$.post("/login/doLogin", {username : username, password : password}, function(data){
				if (data == "success"){
					$.validationEngine.buildPrompt("#form_login #button_login", "登录成功！", "pass");
					window.location.reload(); 
				}  else if (data == "wrong username"){
					$.validationEngine.buildPrompt("#form_login #login_input_username", "您输入的手机号或邮箱不正确，请重新输入。", "error");
				}  else if (data == "wrong password"){
					$.validationEngine.buildPrompt("#form_login #login_input_password", "错误的密码，请重新输入。", "error");
				}  else if (data == "too fast"){
					$.validationEngine.buildPrompt("#form_login #button_login", "您的登录操作过于频繁，请稍候尝试。", "error");
				}  else {
					$.validationEngine.buildPrompt("#form_login #button_login", "登录失败。", "error");
				}
			});
		});
	});
});
</script>
<div id="login_bound">
	<div class="page_column_left_padding15">
		<h1>登录</h1>
		<div class="top"></div>
		<div class="content">
			<form id="form_login">
				<div id="login_mobile">
					<label>用户名</label>
					<input id="login_input_username" type="text" name="mobile" class="validate[required,funcCall[validateUsername]]"></input>
					<span style="padding-left:20px;color:gray;">（用手机号或邮箱登录）</span>
				</div>
				<div id="login_password">
					<label>密码</label>
					<input id="login_input_password" type="password" name="password" class="validate[required,funcCall[validatePassword]]"></input>
				</div>
				<div id="bottom_buttons" style="clear:both;position:relative;">
					<span><a href="/login/forgetPassword" style="position:absolute;left:10px;top:10px;">忘记密码？</a></span>
					<span id="button_login" class="button_login"></span>
				</div>
			</form>
		</div>
		<div class="bottom"></div>
	</div>
</div>
